﻿using LdtJudge.DataEngine.CallInterface.ConfiCenter;
using LdtJudge.DataEngine.DataBaseStores;
using Newtonsoft.Json;
using System;
using System.Web;
using System.Xml;

namespace LdtJudge.DataEngine.Common.DataSave
{
    /// <summary>
    /// 保存读取XML信息
    /// </summary>
    public class XMLDataSave
    {
        /// <summary>
        /// 上下文数据
        /// </summary>
        public DataContext dataContext { get; set; }

        

        /// <summary>
        /// 获取要素结果信息
        /// </summary>
        /// <returns>要素内容</returns>
        public XmlDocument AnalysisDataRead()
        {
            XmlDocument xmlDocument = new XmlDocument();
            //string message=HttpHelp.HttpGet(ConfigRetrieval.GetConfigRetrieval.GetAppSettingString("xmlsaveurl") + "/api/XmlDataManage/GetXmlContent/" + HttpUtility.UrlEncode(dynamicDataStores.dataLayerStores.AnalysisParameter.sourceDossierInfo.SD_ElementPath), "");
            //xmlDocument.LoadXml(message);
            return xmlDocument;
        }

        /// <summary>
        /// 保存优选数据
        /// </summary>
        public void OptimizationDataSave(string xmlname,string xmlcontext) 
        {
            XmlData xmlData = new XmlData();
            xmlData.xmlPath =xmlname;
            xmlData.xmlContent = xmlcontext;
            xmlData.EncryptFlag = 1;
            xmlData.msgID = dataContext.DataLayerAns.MsgId;
            string jsonvalue = JsonConvert.SerializeObject(xmlData);
            string messge = HttpHelp.HttpPostJson(ConfigRetrieval.GetConfigRetrieval.GetAppSettingString("xmlsaveurl") + "/api/XmlDataManage/SaveXml", jsonvalue);
        }

       
        /// <summary>
        /// 读取优选数据
        /// </summary>
        /// <param name="xmlname">路径</param>
        /// <returns></returns>
        public XmlDocument OptimizationRead(string xmlname)
        {
            XmlDocument xmlDocument = new XmlDocument();
            try
            {
                string message = HttpHelp.HttpGet(ConfigRetrieval.GetConfigRetrieval.GetAppSettingString("xmlsaveurl") + "/api/XmlDataManage/GetXmlContent/" + HttpUtility.UrlEncode(xmlname), "");
                xmlDocument.LoadXml(message);
            }
            catch (Exception)
            {

            }
           
            return xmlDocument;
        }
    }

    public class XmlData 
    {
        /// <summary>
        /// xml文件路径
        /// </summary>
        public string xmlPath { get; set; }

        /// <summary>
        /// xml内容
        /// </summary>
        public string xmlContent { get; set; }

        /// <summary>
        /// 是否加密1默认为0
        /// </summary>
        public int EncryptFlag { get; set; }

        public string id { get; set; }

        /// <summary>
        /// 消息ID
        /// </summary>
        public string msgID { get; set; }

        /// <summary>
        /// 案件ID
        /// </summary>
        public string anjid { get; set; }

        /// <summary>
        /// 案件ID
        /// </summary>
        public string anjlx { get; set; }

    }
}
